<?php


// no direct access
defined('_APP') or die('Restricted access');


// Require the base controller
require_once (PATH_APP.DS.'controller.php');

$cmd = Request::getCmd('task', 'display');
if (strpos($cmd, '.') != false)
{
	// We have a defined controller/task pair -- lets split them out
	list($controllerName, $task) = explode('.', $cmd);
}
else
	{
		// Base controller, just set the task :)
		$controllerName = null;
		$task = $cmd;
	}

// Require specific controller if requested
if($controllerName = Request::getVar('controller')) {
	require_once (PATH_APP.DS.'controllers'.DS.$controllerName.'.php');
} else {
	if (strpos($cmd, '.') != false)
	{
		// We have a defined controller/task pair -- lets split them out
		list($controllerName, $task) = explode('.', $cmd);
	
		// Define the controller name and path
		$controllerName	= strtolower($controllerName);
		
		$controllerPath	= PATH_APP.DS.'controllers'.DS.$controllerName.'.php';
	
		// If the controller file path exists, include it ... else lets die with a 500 error
		if (file_exists($controllerPath)) {
			require_once($controllerPath);
		} else {
			appexit('Invalid Controller');
		}
	}
	else
	{
		// Base controller, just set the task :)
		$controllerName = null;
		$task = $cmd;
	}
}

// Set the name for the controller and instantiate it
$controllerClass = 'GFController'.ucfirst($controllerName);
if (class_exists($controllerClass)) {
	$controller = new $controllerClass();
} else {
	appexit('Invalid Controller Class');
}

if (method_exists($controller, $task))
	$controller->$task();



